package com.ymatou.iapi.delivery.testcase;

import java.math.BigDecimal;
import java.util.Arrays;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.delivery.parameter.GetOrderIdsByBillCodeReq;
import com.ymatou.iapi.delivery.service.GetOrderIdsByBillCodeCall;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
/**
*根据物流单号获取订单信息接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getOrderIdsByBillCode {
	private static GetOrderIdsByBillCodeReq bean;
	private static GetOrderIdsByBillCodeCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据物流单号获取订单信息接口");
	}

	@Before
	public void caseUp() {
		bean = new GetOrderIdsByBillCodeReq();
		call = new GetOrderIdsByBillCodeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getOrderIdsByBillCode_001() {
		Logger.start(true, "根据物流单号获取订单信息");
		try {

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithLogisticsType(LogisticsTypeEnum.OVERSEAS_DELIVERY);
			
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			long userId = placeOrderResp.getUserId();

			long tradingId = placeOrderResp.getTradingId();
			
			BigDecimal useAccountAmount = placeOrderResp.getPayableAmount();
			
			TradingCallService.payOrder(userId, useAccountAmount, tradingId);
			
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			Thread.sleep(1000);
			String billCode = TradingCallService.delivery(sellerId, orderId, LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);

			bean.setBillCodes(Arrays.asList(billCode));

			bean.setDeleted(false);
			call.setData(bean);
			call.callService();

			Logger.verifyEquals(call.getString("IsSuccess"), "true",
					"校验IsSuccess");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}